using System;
using System.Collections.Specialized;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MetaBuilders.Irc.Messages;
using MetaBuilders.Irc.Messages.Modes;

namespace MetaBuilders.NeboTests
{

	[TestClass]
	public class ModeTests
	{

		[TestMethod]
		public void ParseOpMode()
		{
			String raw = ":COBOL!~COBOL@ool-435015b7.dyn.optonline.net MODE #ms.net +o artificer";

			IrcMessage ircMsg = MessageParserService.Service.Parse( raw );
			Assert.IsInstanceOfType( ircMsg, typeof( ChannelModeMessage ), "Parses Part" );

			ChannelModeMessage msg = (ChannelModeMessage)ircMsg;
			ChannelModesCreator creator = new ChannelModesCreator();
			creator.Parse( msg );

			Assert.AreEqual( 1, creator.Modes.Count, "Mode Count" );
			Assert.IsInstanceOfType( creator.Modes[0], typeof( OperatorMode ), "Mode Type" );

			OperatorMode mode = (OperatorMode)creator.Modes[ 0 ];
			Assert.AreEqual( ModeAction.Add, mode.Action, "Mode Action" );
			Assert.AreEqual( "artificer", mode.Nick, "Mode Nick" );

			creator.ApplyTo( msg );

			Assert.AreEqual( raw, msg.ToString(), "Round Trip" );
		}

		[TestMethod]
		public void ParseMultiOpMode()
		{
			String raw = ":COBOL!~COBOL@ool-435015b7.dyn.optonline.net MODE #ms.net +oo artificer bob";

			IrcMessage ircMsg = MessageParserService.Service.Parse( raw );
			Assert.IsInstanceOfType( ircMsg, typeof( ChannelModeMessage ), "Parses MODE" );

			ChannelModeMessage msg = (ChannelModeMessage)ircMsg;
			ChannelModesCreator creator = new ChannelModesCreator();
			creator.Parse( msg );

			Assert.AreEqual( 2, creator.Modes.Count, "Mode Count" );
			Assert.IsInstanceOfType( creator.Modes[0], typeof( OperatorMode ), "Mode Type" );
			Assert.IsInstanceOfType( creator.Modes[1], typeof( OperatorMode ), "Mode Type" );

			OperatorMode mode = (OperatorMode)creator.Modes[ 0 ];
			Assert.AreEqual( ModeAction.Add, mode.Action, "Mode Action" );
			Assert.AreEqual( "artificer", mode.Nick, "Mode Nick" );

			mode = (OperatorMode)creator.Modes[ 1 ];
			Assert.AreEqual( ModeAction.Add, mode.Action, "Mode Action" );
			Assert.AreEqual( "bob", mode.Nick, "Mode Nick" );

			creator.ApplyTo( msg );

			Assert.AreEqual( raw, msg.ToString(), "Round Trip" );
		}

	}
}
